package com.hc.pingtan.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.pingtan.mapper.QsAdminMapper;
import com.hc.pingtan.model.QsAdmin;
import com.hc.pingtan.service.IQsAdminService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-09
 */
@Service
@DS("db2")
public class QsAdminServiceImpl extends ServiceImpl<QsAdminMapper, QsAdmin> implements IQsAdminService {

    @Override
    public void createAccount(String accountName) {
        QueryWrapper<QsAdmin> queryWrapper = new QueryWrapper();
        queryWrapper.eq("username", accountName);
        List<QsAdmin> list = this.baseMapper.selectList(queryWrapper);
        if (!list.isEmpty()) {
            return;
        }
        String accountJson = "{\"addTime\":1635051858,\"email\":\"593227174@qq.com\",\"id\":1,\"lastLoginIp\":\"61.151.182.102:27901\"," +
                "\"lastLoginTime\":1635861828,\"password\":\"fc897a08f9485a0d0939f340f5488393\",\"pwdHash\":\"feynsf\",\"roleId\":1,\"username\":\"admin\"}";
        QsAdmin qsAdmin = JSON.parseObject(accountJson, QsAdmin.class);
        qsAdmin.setId(null);
        qsAdmin.setUsername(accountName);
        qsAdmin.setPassword("fc897a08f9485a0d0939f340f5488393");
        this.baseMapper.insert(qsAdmin);
    }
}
